package com.project.controller.custom;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.OrderBean;
import com.project.bean.UserBean;
import com.project.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.print.DocFlavor;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("custom/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;
    @RequestMapping("addOrder")
    public String addOrder(OrderBean orderBean, HttpServletRequest request){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        orderService.add(orderBean,user.getId());
        return "ok";
    }

    @RequestMapping("findAllByID")
    public IPage<OrderBean> findAllByID(HttpServletRequest request,int pageNo){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        return orderService.findAllByID(user.getId(),pageNo);
    }
    @RequestMapping("findById")
    public OrderBean findById(int id){
        return orderService.findById(id);
    }

}
